<!--
* description: 新增编辑-门店级别系数
* author:wangjuan
* createdDate:2020-12-4
-->
<template>
  <section class="editBigAreaInfo">
    <el-dialog
      v-dialogDrag
      :close-on-click-modal="false"
      :title="textMap[popupsState]"
      :append-to-body="true"
      :visible.sync="curPopupsVisible"
      width="70%"
      @close="closeEdit"
    >
      <dialogHeader
        slot="title"
        :title="textMap[popupsState]"
        :style-type="$store.state.app.dialogType"
      />

      <div class="filter-container filter-params">
        <el-row ref="vailComponentList" :gutter="26">
          <!-- <component
            :is="comp.component"
            v-for="comp in tableComponents.filter((o) => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire + comp.compKey : comp.compKey"
            :key="comp.compKey"
            :validrule="comp.validrule"
            :code-field="comp.codeField"
            :text-field="comp.textField"
            :popups-key="comp.compKey"
            :parent-fileds="comp.parentFileds || ''"
            :code="formField[comp.codeField]"
            :disabled="comp.disabled"
            :is-require="comp.isRequire"
            :is-mul="comp.isMul"
            :span="comp.span || 8"
            :label-name="comp.labelName"
            :lookuptype="comp.lookuptype"
            :date-options-type="comp.dateOptionsType"
            @changeCode="getComponentCode"
          /> -->

          <component
            :is="comp.component"
            v-for="comp in tableComponents.filter(o => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire + comp.compKey : comp.compKey"
            :key="comp.compKey"
            :validrule="comp.validrule"
            :code-field="comp.codeField"
            :text-field="comp.textField"
            :popups-key="comp.compKey"
            :parent-fileds="comp.parentFileds"
            :code="formField[comp.codeField]"
            :disabled="comp.disabled"
            :o-fields="comp.oFields"
            :options="comp.options"
            :custom-obj="comp.customObj"
            :is-require="comp.isRequire"
            :is-mul="comp.isMul"
            :span="comp.span || 8"
            :label-name="comp.labelName"
            :lookuptype="comp.lookuptype"
            :data-to-object="comp.dataToObject"
            :date-options-type="comp.dateOptionsType"
            @changeCode="getComponentCode"
            @focusCode="getFocusCode"
          />
        </el-row>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button
          v-for="comp in tableButtons"
          :key="comp.compKey"
          :type="comp.type"
          :icon="comp.icon"
          @click="comp.clickEvent"
          >{{ comp.text }}</el-button
        >
      </div>
    </el-dialog>
  </section>
</template>
<script>
import { formMixins } from "@/components/mixins/formMixins";
import { vehiclePdiPriceInquirys } from "@/api/se/vehiclePdiPriceInquiry";

export default {
  components: {
    dialogHeader: () => import("@/components/dialogHeader"),
    mixButton: () => import("@/components/basicComponent/mixButton")
  },

  // 组件混入对象
  mixins: [formMixins],

  props: {
    popupsVisible: { type: Boolean, default: false },
    // 从网格传入的编辑行数据(json)
    dynamicEditRowData: {
      type: Object,
      default: function() {
        return {};
      }
    }
  },

  data() {
    const viewPageCode = "bigAreaInfo-edit";
    return {
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          icon: "iconfont  icon-preservation",
          clickEvent: () => this.save(),
          text: this.$t("sys.button.save") /* 保存*/,
          position: "right"
        },
        {
          compKey: "btnKey2",
          type: "",
          size: "small",
          icon: "iconfont  icon-cancel",
          clickEvent: () => this.close(),
          text: this.$t("sys.button.cancel") // 取消
        }
      ],

      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode] &&
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode].formComponents
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[viewPageCode].formComponents
          : [
              {
                compKey: "compKey1",
                labelName: "门店编码：",
                codeField: "dlrCode",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isRequire: true,
                isMust: true,
                disabled: true
              },
              {
                compKey: "compKey2",
                labelName: "门店名称：",
                codeField: "dlrFullName",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isRequire: true,
                isMust: true,
                disabled: true
              },
              {
                compKey: "compKey3",
                labelName: "门店级别：",
                codeField: "dlrLevel",
                component: () => import("@/components/org/commonSelect"),
                customObj: {
                  api: vehiclePdiPriceInquirys.repairType
                },
                oFields: "lookupValueCode,lookupValueName",
                type: "dropdownList",
                isMul: false,
                isMust: true
              },
              {
                compKey: "compKey4",
                labelName: "PDI价格系数：",
                codeField: "pdiCoef",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: true,
                isRequire: true,
                validrule: {
                  noRequire: false,
                  // isformat: /^[0-9][0-9]*([\.][0-9]{1,2})?$/
                  isformat: /^([1-9]\d*(\.\d{1,3})?|([0](\.([0][1-9]|[1-9]\d{0,2}))))$/
                }
              },
              {
                compKey: "compKey5",
                labelName: "索赔工时系数：",
                codeField: "claimWiCoef",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: true,
                isRequire: true,
                validrule: {
                  noRequire: false,
                  // isformat: /^[1-9][0-9]*([\.][0-9]{1,2})?$/
                  isformat: /^([1-9]\d*(\.\d{1,3})?|([0](\.([0][1-9]|[1-9]\d{0,2}))))$/
                }
              },
              {
                compKey: "compKey6",
                labelName: "索赔备件系数：",
                codeField: "claimPartCoef",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: true,
                isRequire: true,
                validrule: {
                  noRequire: false,
                  // isformat: /^[1-9][0-9]*([\.][0-9]{1,2})?$/
                  isformat: /^([1-9]\d*(\.\d{1,3})?|([0](\.([0][1-9]|[1-9]\d{0,2}))))$/
                }
              },
              {
                compKey: "compKey7",
                labelName: "工时授权折扣：",
                codeField: "discountWi",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: true,
                isRequire: true,
                validrule: {
                  noRequire: false,
                  isformat: /^(1|1\.[0]*|0?\.(?!0+$)[\d]+)$/
                }
              },
              {
                compKey: "compKey8",
                labelName: "备件授权折扣：",
                codeField: "discountPart",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: true,
                isRequire: true,
                validrule: {
                  noRequire: false,
                  isformat: /^(1|1\.[0]*|0?\.(?!0+$)[\d]+)$/
                }
              },
              {
                compKey: "compKey9",
                labelName: "工单授权折扣：",
                codeField: "discountOrder",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: true,
                
                isRequire: true,
                validrule: {
                  noRequire: false,
                  isformat: /^(1|1\.[0]*|0?\.(?!0+$)[\d]+)$/
                }
              },
              {
                compKey: "compKey10",
                labelName: "结算工时系数：",
                codeField: "balanceWiCoef",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: true,
                isRequire: true,
                validrule: {
                  noRequire: false,
                  isformat: /^[0-9]*([\.][0-9]{1,3})?$/
                }
              },
              {
                compKey: "compKey11",
                labelName: "是否允许首保：",
                codeField: "isFirstMaintain",
                component: () => import("@/components/org/LookupValue"),
                type: "dropdownList",
                oFields: "statusId,statusText",
                options: [
                  { statusId: "1", statusText: "是" },
                  { statusId: "0", statusText: "否" }
                ],
                isMust: true
              },

              {
                compKey: "compKey12",
                labelName: "是否允许保修：",
                codeField: "isRepair",
                component: () => import("@/components/org/LookupValue"),
                oFields: "statusId,statusText",
                options: [
                  { statusId: "1", statusText: "是" },
                  { statusId: "0", statusText: "否" }
                ],
                type: "dropdownList",
                isMul: false,
                isMust: true
              },
              {
                compKey: "compKey13",
                labelName: "是否允许权益：",
                codeField: "isActives",
                component: () => import("@/components/org/LookupValue"),
                type: "dropdownList",
                oFields: "statusId,statusText",
                options: [
                  { statusId: "1", statusText: "是" },
                  { statusId: "0", statusText: "否" }
                ],
                isMust: true
              },
              {
                compKey: "compKey14",
                labelName: "状态：",
                codeField: "isEnable",
                component: () => import("@/components/org/LookupValue"),
                type: "dropdownList",
                oFields: "statusId,statusText",
                options: [
                  { statusId: "1", statusText: "可用" },
                  { statusId: "0", statusText: "禁用" }
                ],
                isMust: true
              }
            ],

      // 标题
      textMap: {
        edit: "门店级别系数维护"
      },

      // 表单数据（无需赋值，由混入对象赋值）
      formField: this.$utils.getFormField(
        this,
        {
          dlrCode: "",
          dlrFullName: "",
          dlrLevel: "",
          pdiCoef: "",
          claimWiCoef: "",
          claimPartCoef: "",
          discountWi: "",
          discountPart: "",
          discountOrder: "",
          balanceWiCoef: "",
          isFirstMaintain: "",
          isFirstMaintainCn: "",
          isRepair: "",
          isRepairCn: "",
          isActives: "",
          isActivesCn: "",
          isEnable: "",
          isEnableCn: "",
          dlrSetId: "",
          lookupValueName:"",
          dlrLevel: "",
        },
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode]
      )
    };
  },

  methods: {
    // 关闭弹窗
    // handleClose(done) {
    //   this.$confirm('还未保存，确认关闭窗口？')
    //     .then(_ => {
    //       this.$emit('update:curPopupsVisible', false)
    //       done()
    //     })
    //     .catch(_ => {})
    // },
    closeEdit() {
      this.curPopupsVisible = false;
      this.$emit("update:curPopupsVisible", false);
      this.$emit("close", false);
    },
    // 保存按钮
    save() {
      this.$utils.validataMoth(this, "validpopup");
      if (this.valid) {
        const queryObj = {
          // 保存mutation
          type: "mutation",
          // api配置
          apiConfig: {
            ServiceCode: "editBigArea",
            APIUrl: "/mp/e3sh/aftersale/DlrParamSetService/updateDlrParamSet.do"
          },
          // 条件/实体参数（变量），根据typeParam中的定义配置
          variables: this.formField
        };
        // 转换了中台请求格式数据
        var paramD = this.$getParams(queryObj);
        // 调用中台API方法（可复用）
        this.$requestAPI(paramD).then(response => {
          if (response.result === "1") {
            this.$message({
              message: this.$t("sys.tips.esTip5") /* 保存成功*/,
              type: "success",
              duration: 1000
            });
            this.curPopupsVisible = false;
            this.$nextTick(() => {
              this.$parent.queryTable(1);
            });
          } else {
            // 保存失败
            this.$message({
              message: "保存失败:" + response.msg,
              type: "warn",
              uration: 1000
            });
          }
          this.curPopupsVisible = false;
        });
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.promptSpan {
  position: absolute;
  bottom: 26px;
  right: 335px;
  color: #e70020;
}
</style>

